//
//  YRVisitorTableViewController.swift
//  新浪微博
//
//  Created by Viper on 16/6/25.
//  Copyright © 2016年 Viper. All rights reserved.
//

import UIKit

class YRVisitorTableViewController: UITableViewController {

    //判断用户是否登录
    var isLogin : Bool = YRUserAccountTools.sharedTools.isLogin
    
    //访客视图对象(延迟创建在需要的时候创建)
    var visitorView : YRVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func loadView() {
        
        if isLogin {
            //代表登录
            super.loadView()
        }else{
            
            setupVisitorView()
           
        }
    }
    
    //MARK: - 设置访客视图
    
    private func setupVisitorView(){
        
        setupNav()
        
        visitorView = YRVisitorView()
        
        visitorView?.closure = {[weak self] in
            
            self?.logoinBtnClick()
        }
        view = visitorView
        
    }
    
    //MARK: - 设置导航栏
    private func setupNav(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(YRVisitorTableViewController.logoinBtnClick))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(YRVisitorTableViewController.logoinBtnClick))
        
    }
    

    func logoinBtnClick(){
        
        let oauthVC = YROAuthViewController()
        let naVC = UINavigationController(rootViewController: oauthVC)
        
        presentViewController(naVC, animated: true, completion: nil)
        
    }
    
    
}
